package builder.trainer.counter;

import java.util.ArrayList;
import java.util.HashMap;

public class AttributeValue {

	private String value;
	private ArrayList<Integer> indexes;
	private HashMap<String, Integer> objValues;
	private double entropy;
	
	
	private Counter counter;
	
	public AttributeValue(String valueName,Counter counter) {
		this.setIndexes(new ArrayList<Integer>());
		this.value = valueName;
		this.counter = counter;
	}
	
	public AttributeValue() {
		this.setIndexes(new ArrayList<Integer>());
	}

	public HashMap<String, Integer> getObjectValues(int objColumn) {
		if (this.objValues != null)
			return this.objValues;
		this.objValues = new HashMap<String, Integer>();
		for (int index : indexes) {
			String[] record = this.counter.getRecord(index);
			String sValue = record[objColumn].trim();
			Integer value = this.objValues.get(sValue);
			value = (value == null) ? 1 : value + 1;
			this.objValues.put(sValue, value);
		}
		return this.objValues;
	}

	public int getCount() {
		return this.getIndexes().size();
	}

	public void setValueName(String valueName) {
		this.value = valueName;
	}

	public String getValueName() {
		return value;
	}

	private void setIndexes(ArrayList<Integer> indexes) {
		this.indexes = indexes;
	}

	public ArrayList<Integer> getIndexes() {
		return indexes;
	}

	public void addIndex(int numRecord) {
		this.indexes.add(numRecord);
	}

	public void setEntropy(double entropy) {
		this.entropy = entropy;
	}

	public double getEntropy() {
		return this.entropy;
	}
}
